<template>
  <div id="cell">
    <van-cell>
      <div class="container">
        <div class="img">
          <van-image
            lazy-load
            fit="cover"
            :src="item.images && item.images[0]"
            @click="checkPic(item.images[0] || '')"
          />
        </div>
        <div class="content" @click="$emit('goArticleContent', item)">
          <div class="title">
            <van-tag round color="#ffe1e1" text-color="#ad0000">{{
              label.name
            }}</van-tag
            >{{ item.title }}
          </div>
          <div class="introduction">
            <p>{{ processData(item.content) }}</p>
          </div>
          <div class="articleInfo">
            <span>
              <van-icon color="seagreen" name="smile-o" />--{{
                item.author.name
              }}</span
            >
            <span>{{ calcDate(item.updateTime) }}</span>
          </div>
        </div>
      </div>
    </van-cell>
  </div>
</template>

<script>
import { ImagePreview } from 'vant'
import moment from 'moment'
export default {
  props: {
    item: {
      type: Object,
      required: true
    },
    label: {
      type: Object,
      required: true
    }
  },
  methods: {
    calcDate(date) {
      moment.locale('zh-cn')
      return moment(date).fromNow()
    },
    checkPic(img) {
      ImagePreview([img])
    },
    processData(str) {
      const reg = /<\/?.+?\/?>/g
      return str.replace(reg, '')
    }
  }
}
</script>

<style scoped lang="less">
.van-cell {
  margin: 10px 0;
}
.container {
  height: 130px;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 2fr;
  .img {
    height: 100%;
    .van-image {
      width: 100%;
      height: 100%;
    }
  }
  .content {
    height: 100%;
    margin-left: 15px;
    .title {
      font-size: 16px;
      font-weight: 500;
      text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      line-clamp: 1;
      -webkit-box-orient: vertical;
      .van-tag {
        margin-right: 15px;
      }
    }
    .introduction {
      height: 64px;
      p {
        margin: 10px;
        text-overflow: -o-ellipsis-lastline;
        max-height: 60px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        p {
          /deep/ img {
            display: none;
          }
          /deep/ pre {
            display: none;
          }
        }
        /deep/ pre {
          display: none;
        }
        /deep/ img {
          display: none;
        }
      }
    }
    .articleInfo {
      display: flex;
      justify-content: space-between;
    }
  }
}
</style>
